package com.dcshop.demo.controller;//package com.xbox.consumer.controller;


import com.github.ontio.OntSdk;
import com.github.ontio.account.Account;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * UserController
 * 查询登录用户信息
 */
@RestController
public class UserController extends AbsController {

    /**
     * 注册ontid
     *
     * @param reqMap
     * @return
     */
    @PostMapping("/userLogin")
    public Boolean userLogin(@RequestBody Map<String, Object> reqMap) {

        String username = reqMap.get("username").toString();
        String password = reqMap.get("password").toString();


        if (StringUtils.isEmpty(username)) {
            return false;
        }
        if (StringUtils.isEmpty(password)) {
            return false;
        }

        //TODO username 转换为ontid

        String ontId = queryOntidByUsename(username);

        OntSdk ontSdk = null;

        try {
            ontSdk = getOntSdk();

            Account payAccount = getPlatformAccount(ontSdk);

            //TODO 客户在登陆系统的时候会取到productOwerAccount，测试先用payAccount
            Account productOwerAccount = payAccount;


            if (productOwerAccount != null) {
                return true;
            }

        } catch (Exception e) {
            System.out.println(e.getMessage());
            return false;
        }

        return false;

    }


}
